home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / display.cpp < prev    next >
C/C++ Source or Header  |  1996-02-21  |  13KB  |  525 lines

  1. /******************************************************************************
  2. *******************************************************************************
  3.  
  4. Display output routines...
  5.  
  6. ******************************************************************************
  7. *****************************************************************************/
  8.  
  9. #include "global.h"
  10.  
  11. #include "defines.h"
  12. #include "externs.h"
  13. #include "mouse.h"
  14. #include "time.h"
  15. #include "3deng.h"
  16.  
  17. extern int scale;
  18. extern char camera;
  19. extern int play_cam;
  20. extern buff_info main_buff,vidi_buff;
  21. extern plyrdat pos[];
  22.  
  23. /*****************************************************************************
  24. *****************************************************************************/
  25.  
  26. /*****************************************************************************
  27. *****************************************************************************/
  28.  
  29. void init_pitch_sprites()
  30. {
  31.     pitch_sprs=0;
  32.     spr_coord_tab[0]=0;
  33. }
  34.  
  35. /*****************************************************************************
  36. *****************************************************************************/
  37.  
  38. void add_pitch_sprite(short x,short y,short z,short ref)
  39. {
  40. // Set up real 3d sprite...
  41.     spr_coord_tab[0]+=1;
  42.     spr_coord_tab[3*pitch_sprs+1]=x;
  43.     spr_coord_tab[3*pitch_sprs+2]=z;
  44.     spr_coord_tab[3*pitch_sprs+3]=-y;
  45.     spr_ref_tab[pitch_sprs++]=ref;
  46. }
  47.  
  48. /******************************************************************************
  49. *****************************************************************************/
  50.  
  51. void grid_map()
  52. {
  53.     int c=_getcolor();
  54.     int g=_getplotaction();
  55.     _setcolor(2);
  56.     _setplotaction(_GXOR);
  57.     float step=(320.2)/7;
  58.     float step2=step*224/320;
  59.     float x=0+(step/2);
  60.     float x2=48+(step2/2);
  61.     for (int i=1; i<8; i++, x+=step, x2+=step2 )
  62.     {
  63.         _moveto((int)x,131);
  64.         _lineto((int)x2,32);
  65.     }
  66.     step=100/3;
  67.     float lstep=48/3;
  68.     x=32+(step/2);
  69.     float lx=48-(lstep/2);
  70.     for (i=1; i<4; i++, x+=step, lx-=lstep )
  71.     {
  72.         _moveto(lx,(int)x);
  73.         _lineto(272+(47-lx),(int)x);
  74.     }
  75.     _setcolor(c);
  76.     _setplotaction(g);
  77. }
  78.  
  79. /******************************************************************************
  80. ******************************************************************************/
  81.  
  82. void line_border(int x,int y,int wid,int hgt,int col)
  83. {
  84.     int c=_getcolor();
  85.     _moveto(x,y);
  86.     _setcolor(col);
  87.     _lineto(x+wid-1,y);
  88.     _lineto(x+wid-1,y+hgt-1);
  89.     _lineto(x,y+hgt-1);
  90.     _lineto(x,y);
  91.     _setcolor(c);
  92. }
  93.  
  94. /******************************************************************************
  95. *****************************************************************************/
  96.  
  97. void draw_buttons()
  98. {
  99.     int x,y,w;
  100.     char st[10];
  101.     for (int i=0; i<max_butts; i++)
  102.     {
  103.         x=us_buttons[i].x;
  104.         y=us_buttons[i].y;
  105.         w=us_buttons[i].w;
  106.         strcpy(st,us_buttons[i].s);
  107.         _moveto(x,y);
  108.         _outgtext(st);
  109.         line_border(x-4,y-4,w*8+8,16,1);
  110.     }
  111. }
  112.  
  113. /******************************************************************************
  114. *****************************************************************************/
  115.  
  116. void light_button(int b)
  117. {
  118.     int x,y,w,c;
  119.     c=_getcolor();
  120.     char st[10];
  121.     x=us_buttons[b].x;
  122.     y=us_buttons[b].y;
  123.     w=us_buttons[b].w;
  124.     strcpy(st,us_buttons[b].s);
  125.     _setcolor(7);
  126.     _moveto(x,y);
  127.     HideMouse();
  128.     _outgtext(st);
  129.     _setcolor(c);
  130.     ShowMouse();
  131.     button_lit=b+1;
  132. }
  133.  
  134. /******************************************************************************
  135. *****************************************************************************/
  136.  
  137. void unlight_button(int b)
  138. {
  139.     int x,y,w;
  140.     char st[10];
  141.     x=us_buttons[b].x;
  142.     y=us_buttons[b].y;
  143.     w=us_buttons[b].w;
  144.     strcpy(st,us_buttons[b].s);
  145.     _moveto(x,y);
  146.     HideMouse();
  147.     _outgtext(st);
  148.     ShowMouse();
  149.     if (button_lit==b+1)
  150.         button_lit=0;                    //no other button lit!
  151. }
  152.  
  153. /******************************************************************************
  154. *****************************************************************************/
  155.  
  156. void conv_xypitch(float x, float y, int *screen_x, int *screen_y)
  157. {
  158.     float x2,xoff;
  159.     x2=x;
  160.     x=-(x-halfway_line);
  161.     xoff=scr_pinch*(((float)pitch_wid-y)/(50.0*16))*x/(40.0*16.0);
  162.     x2=(x2/4)+xoff;
  163.     *screen_x=x2;
  164.     *screen_y=(y/8);
  165. }
  166.  
  167. /******************************************************************************
  168. ****************************************************************************/
  169.  
  170. void pitch_markings()
  171. {
  172.     int g=_getplotaction();
  173.     int c=_getcolor();
  174.     int x,y;
  175.     _setcolor(7);
  176.  
  177. // Left Goal
  178.     conv_xypitch(0,357,&x,&y);
  179.     _moveto(x,y+32);
  180.     _lineto(x,y+32-4);
  181.     _moveto(x,y+32);
  182.     conv_xypitch(-28,357,&x,&y);
  183.     _lineto(x,y+32);
  184.     _lineto(x,y+32-4);
  185.     _moveto(x,y+32);
  186.     conv_xypitch(-28,443,&x,&y);
  187.     _lineto(x,y+32);
  188.     _lineto(x,y+32-4);
  189.     _moveto(x,y+32);
  190.     conv_xypitch(0,443,&x,&y);
  191.     _lineto(x,y+32);
  192.     _lineto(x,y+32-4);
  193.     conv_xypitch(0,357,&x,&y);
  194.     _lineto(x,y+32-4);
  195.     conv_xypitch(-28,357,&x,&y);
  196.     _lineto(x,y+32-4);
  197.     conv_xypitch(-28,443,&x,&y);
  198.     _lineto(x,y+32-4);
  199.     conv_xypitch(0,443,&x,&y);
  200.     _lineto(x,y+32-4);
  201.  
  202. // Right Goal
  203.     conv_xypitch(pitch_len,357,&x,&y);
  204.     _moveto(x,y+32);
  205.     _lineto(x,y+32-4);
  206.     _moveto(x,y+32);
  207.     conv_xypitch(pitch_len+28,357,&x,&y);
  208.     _lineto(x,y+32);
  209.     _lineto(x,y+32-4);
  210.     _moveto(x,y+32);
  211.     conv_xypitch(pitch_len+28,443,&x,&y);
  212.     _lineto(x,y+32);
  213.     _lineto(x,y+32-4);
  214.     _moveto(x,y+32);
  215.     conv_xypitch(pitch_len,443,&x,&y);
  216.     _lineto(x,y+32);
  217.     _lineto(x,y+32-4);
  218.     conv_xypitch(pitch_len,357,&x,&y);
  219.     _lineto(x,y+32-4);
  220.     conv_xypitch(pitch_len+28,357,&x,&y);
  221.     _lineto(x,y+32-4);
  222.     conv_xypitch(pitch_len+28,443,&x,&y);
  223.     _lineto(x,y+32-4);
  224.     conv_xypitch(pitch_len,443,&x,&y);
  225.     _lineto(x,y+32-4);
  226.  
  227.     _setcolor(1);
  228. // Left Six Yard Box
  229.     conv_xypitch(0,293,&x,&y);
  230.     _moveto(x,y+32);
  231.     conv_xypitch(6.0*prat,293,&x,&y);
  232.     _lineto(x,y+32);
  233.     conv_xypitch(6.0*prat,507,&x,&y);
  234.     _lineto(x,y+32);
  235.     conv_xypitch(0,507,&x,&y);
  236.     _lineto(x,y+32);
  237.  
  238. // Right Six Yard Box
  239.     conv_xypitch(80*16,293,&x,&y);
  240.     _moveto(x,y+32);
  241.     conv_xypitch(80*16-(6.0*prat),293,&x,&y);
  242.     _lineto(x,y+32);
  243.     conv_xypitch(80*16-(6.0*prat),507,&x,&y);
  244.     _lineto(x,y+32);
  245.     conv_xypitch(80*16,507,&x,&y);
  246.     _lineto(x,y+32);
  247.  
  248. // Left 18 Yard Box
  249.     conv_xypitch(0,208,&x,&y);
  250.     _moveto(x,y+32);
  251.     conv_xypitch(18.0*prat,208,&x,&y);
  252.     _lineto(x,y+32);
  253.     conv_xypitch(18.0*prat,592,&x,&y);
  254.     _lineto(x,y+32);
  255.     conv_xypitch(0,592,&x,&y);
  256.     _lineto(x,y+32);
  257.  
  258. // Right 18 Yard Box
  259.     conv_xypitch(80*16,208,&x,&y);
  260.     _moveto(x,y+32);
  261.     conv_xypitch(80*16-(18.0*prat),208,&x,&y);
  262.     _lineto(x,y+32);
  263.     conv_xypitch(80*16-(18.0*prat),592,&x,&y);
  264.     _lineto(x,y+32);
  265.     conv_xypitch(80*16,592,&x,&y);
  266.     _lineto(x,y+32);
  267.  
  268.  
  269. // Centre circle
  270.     _ellipse(_GBORDER,160-13,82-13,160+13,82+13);
  271.     _setcolor(c);
  272.     _setplotaction(g);
  273. }
  274.  
  275. /******************************************************************************
  276. ****************************************************************************/
  277.  
  278. void draw_pitch()
  279. {
  280.     _setcolor(0);
  281.     _lineto(48,32);
  282.     _setcolor(1);
  283.     _lineto(48+112+111,32);
  284.     _lineto(319,131);
  285.     _lineto(0,131);
  286.     _lineto(48,32);
  287.     _lineto(160,32);
  288.     _lineto(160,131);
  289. }
  290.  
  291. /******************************************************************************
  292. *****************************************************************************/
  293.  
  294. void pitch_plot(int x,int y,int z,char c,char a)        //Place screen coords on plot buffer.
  295. {
  296.     if (plot_buffer)                            //Choose Buffer.
  297.     {
  298.     scr_a[plot_cnta][0]=x;
  299.     scr_a[plot_cnta][1]=y-(z/8);
  300.     scr_a[plot_cnta][2]=c;
  301.     scr_a[plot_cnta++][3]=a;
  302.     }
  303.     else
  304.     {
  305.     scr_b[plot_cntb][0]=x;
  306.     scr_b[plot_cntb][1]=y-(z/8);
  307.     scr_b[plot_cntb][2]=c;
  308.     scr_b[plot_cntb++][3]=a;
  309.     }
  310. }
  311.  
  312. /******************************************************************************
  313. *****************************************************************************/
  314.  
  315. void draw_buffer()
  316. {
  317.     char pn[3]="  ";
  318.     for (int coords=1; (plot_buffer) ? coords<plot_cnta : coords<plot_cntb;
  319.                 coords++)
  320.     {
  321.         if (plot_buffer)                            //Choose Buffer.
  322.         {
  323.             if (scr_a[coords][3]==0)
  324.             {
  325.                 _setcolor(scr_a[coords][2]);
  326.                 _setpixel(scr_a[coords][0],scr_a[coords][1]);
  327.             }    
  328.             else
  329.             {
  330.                 _setcolor(scr_a[coords][2]);
  331.                 _moveto(scr_a[coords][0]-3,scr_a[coords][1]-3);
  332.                 sprintf(pn,"%d",scr_a[coords][3]);
  333.                 _outgtext(pn);
  334.             }
  335.         }
  336.         else
  337.         {
  338.             if (scr_b[coords][3]==0)
  339.             {
  340.                 _setcolor(scr_b[coords][2]);
  341.                 _setpixel(scr_b[coords][0],scr_b[coords][1]);
  342.             }    
  343.             else
  344.             {
  345.                 _setcolor(scr_b[coords][2]);
  346.                 _moveto(scr_b[coords][0]-3,scr_b[coords][1]-3);
  347.                 sprintf(pn,"%d",scr_b[coords][3]);
  348.                 _outgtext(pn);
  349.             }
  350.         }
  351.     }
  352. }
  353.  
  354. /******************************************************************************
  355. *****************************************************************************/
  356.  
  357. void draw_ball()
  358. {
  359.     float bx=(pos+25)->x;
  360.     float bz=((pos+25)->y);
  361.     float by=((pos+25)->z);
  362.     conv_xypitch(bx,by,&scr_x,&scr_y);
  363.     pitch_plot(scr_x,scr_y+32,(int)bz,ball_col,0);
  364.     pitch_plot(scr_x,scr_y+31,(int)bz,ball_col,0);
  365.     pitch_plot(scr_x+1,scr_y+32,(int)bz,ball_col,0);
  366.     pitch_plot(scr_x+1,scr_y+31,(int)bz,ball_col,0);
  367.     pitch_plot(scr_x,scr_y+32,0,shadow_col,0);
  368.     pitch_plot(scr_x+1,scr_y+32,0,shadow_col,0);
  369. }
  370.  
  371. /******************************************************************************
  372. *****************************************************************************/
  373.  
  374. void draw_team()
  375. {
  376.     float tx,ty,tz;
  377.  
  378.     for (int i=0; i<(players/2); i++)
  379.     {
  380.         tx=(pos+i)->x;
  381.         tz=(pos+i)->y;
  382.         ty=(pos+i)->z;
  383.         conv_xypitch(tx,ty,&scr_x,&scr_y);
  384.         if (play_nums_on)
  385.         {
  386.             pitch_plot(scr_x,scr_y+32,(int)tz,team_a_col,i+2);
  387.         }
  388.         else
  389.         {
  390.         pitch_plot(scr_x,scr_y+32,(int)tz,team_a_col,0);
  391.         pitch_plot(scr_x,scr_y+33,(int)tz,team_a_col,0);
  392.         if ((teams[i].int_cnt) && (teams[i].int_move==I_INTERCEPT))
  393.             pitch_plot(scr_x,scr_y+31,(int)tz,7,0);
  394.         }
  395.     }
  396.  
  397.     for (i=11; i<players; i++)
  398.     {
  399.         tx=(pos+i)->x;
  400.         tz=(pos+i)->y;
  401.         ty=(pos+i)->z;
  402.         conv_xypitch(tx,ty,&scr_x,&scr_y);
  403.         if (play_nums_on)
  404.         {
  405.             pitch_plot(scr_x,scr_y+32,(int)tz,team_b_col,i-8);
  406.         }
  407.         else
  408.         {
  409.         pitch_plot(scr_x,scr_y+32,(int)tz,team_b_col,0);
  410.         pitch_plot(scr_x,scr_y+33,(int)tz,team_b_col,0);
  411.         if ((teams[i].int_cnt) && (teams[i].int_move==I_INTERCEPT))
  412.             pitch_plot(scr_x,scr_y+31,(int)tz,7,0);
  413.         }
  414.     }
  415. }
  416.  
  417. /******************************************************************************
  418. *****************************************************************************/
  419.  
  420. void panel_data()
  421. {
  422.     char info_str1[40];
  423.     char info_str2[40];
  424.     char info_str3[4];
  425.     char info_str4[12];
  426. /*
  427. //    sprintf(info_str1,"zone =%d  poss =%d     ",ball_zone1,ball_poss);
  428.     sprintf(info_str1,"opps =%d  poss =%d     ",opponents_near_holder,ball_poss);
  429. //    sprintf(info_str1,"a =%d  b =%d     ",interceptor_a+1,interceptor_b+1);
  430. //    sprintf(info_str2,"last =%d  bspd =%d     ",last_touch,ball_speed);
  431.     sprintf(info_str2,"xyspin =%d zspin =%d     ",set_xyspin,set_zspin);
  432.     _settextposition(21,0);
  433.     _outtext(info_str1);
  434.     _settextposition(22,0);
  435.     _outtext(info_str2);
  436.     _settextposition(23,0);
  437.     _outtext(action);
  438.     _outtext("          ");
  439. */
  440.     sprintf(info_str4,"%d - %d     ",team_a_goals,team_b_goals);
  441.     _settextposition(20,0);
  442.     _outtext(info_str4);
  443.  
  444.     sprintf(info_str3,"%d ",delay_cnt);
  445.     _settextposition(20,37);
  446.     _outtext(info_str3);
  447. }
  448.  
  449. /******************************************************************************
  450. ******************************************************************************/
  451.  
  452. void slower()
  453. {
  454.     delay_cnt++;
  455. }
  456.  
  457. /******************************************************************************
  458. ******************************************************************************/
  459.  
  460. void faster()
  461. {
  462.     if (delay_cnt>0)
  463.         delay_cnt--;
  464. }
  465.  
  466. /******************************************************************************
  467. ******************************************************************************/
  468.  
  469. void show_nums()
  470. {
  471.     if (play_nums_on)
  472.         play_nums_on=FALSE;
  473.     else
  474.         play_nums_on=TRUE;
  475. }
  476.  
  477. /******************************************************************************
  478. *****************************************************************************/
  479.  
  480. int old_time=0;
  481. int prev_count=0;
  482. int times=0;
  483.  
  484. void frame_count()
  485. {
  486.     updates++;
  487.     frames++;
  488.     times++;
  489.  
  490.     int cl=count-oldcnt;
  491.  
  492.     if (count-prev_count>TIMER_SPEED)
  493.     {
  494.         prev_count=count;
  495.         old_time=times;
  496.     }
  497.  
  498.     if (cl>(TIMER_SPEED/4))            // Re-time interval (1/4 sec)!
  499.     {
  500.         oldcnt=count;
  501.         MF=((float)cl*game_speed)/(frames*TIMER_SPEED);
  502.         if (MF>6 && game_speed==REAL_SPEED)
  503.             MF=6;
  504.         frames=0;
  505.     }
  506. }
  507.  
  508. void oframe_count()
  509. {
  510.     updates++;
  511.     int cl=clock();
  512.     frames++;
  513.     int c=cl/CLOCKS_PER_SEC;
  514.     if (c!=last_second)
  515.     {
  516.         seconds++;
  517.         frms_per_sec=frames;
  518.         frames=0;
  519.         last_second=c;
  520.         int frame_time=cl-old_clock;
  521.         old_clock=cl;
  522.         MF=((float)(frame_time)*game_speed)/(frms_per_sec*100);
  523.     }
  524. }
  525.